package com.wc.codeforces.模拟.Secret_Box;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/22 9:16
 * @description https://codeforces.com/problemset/problem/1985/E
 */
public class Main {
    /**
     * 暴力枚举两条边, 以最大的边, 或者是小边可以
     * 让 x <= n, y <= m, z <= g && k = x * y * z
     * 枚举 x, y, 时间复杂度O(n^2)
     * res = max(res, (n - x + 1) * (m - y + 1) * (g - z + 1);
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 4;
    static int[] a = new int[N];
    static long k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            for (int i = 1; i <= 3; i++) a[i] = sc.nextInt();
            k = sc.nextLong();
            Arrays.sort(a, 1, N);
            int n = a[3], m = a[2];
            long res = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (k % (i * j) == 0) {
                        long t = k / i / j;
                        if (t <= a[1])
                            res = Math.max(res, (long) (n - i + 1) * (m - j + 1) * (a[1] - t + 1));
                    }
                }
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
